package com.hw.core.system.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;




@Entity
@Table(name = "user_course")
@Document(indexName="jwxt",type="course")
public class Course implements Serializable{
  private static final long serialVersionUID = 2L;

  @Id
  @GeneratedValue
  private Integer id;
  private String name;
  @Column(name = "p_id")
  private Integer pId;
  private String img;


  @ManyToMany(fetch = FetchType.EAGER,cascade = CascadeType.REMOVE)
  @JoinTable(name="user_course_courseType",joinColumns={@JoinColumn(name="c_id")},
          inverseJoinColumns={@JoinColumn(name="t_id")})
  @NotFound(action= NotFoundAction.IGNORE)
  private List<CourseType> courseTypes;



  @OneToOne

  @JoinTable(name="user_course_courseAuthor",joinColumns={@JoinColumn(name="c_id")},
          inverseJoinColumns={@JoinColumn(name="u_id")})
  @NotFound(action= NotFoundAction.IGNORE)
  private User author;

  public User getAuthor() {
    return author;
  }

  public void setAuthor(User author) {
    this.author = author;
  }

  @Column(name = "text" , columnDefinition = "TEXT" )
  private String text;

  //为1所有人可见
  private Integer status;

  public Integer getStatus() {
    return status;
  }

  public void setStatus(Integer status) {
    this.status = status;
  }

  public Course() {
  }
  public Course(Integer id) {
    this.id=id;
  }

  public Course(Integer id,String name, Integer pId) {
    this.id=id;
    this.name = name;
    this.pId = pId;
  }

  public List<CourseType> getCourseTypes() {
    return courseTypes;
  }

  public void setCourseTypes(List<CourseType> courseTypes) {
    this.courseTypes = courseTypes;
  }

  public Integer getId() {
    return id;
  }

  public void setId(Integer id) {
    this.id = id;
  }


  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }


  public Integer getPId() {
    return pId;
  }

  public void setPId(Integer pId) {
    this.pId = pId;
  }

  public String getImg() {
    return img;
  }

  public void setImg(String img) {
    this.img = img;
  }



  public String getText() {
    return text;
  }

  public void setText(String text) {
    this.text = text;
  }

  @Override
  public String toString() {
    return "Course{" +
            "id=" + id +
            ", name='" + name + '\'' +
            ", pId=" + pId +
            ", img='" + img + '\'' +
            ", courseTypes=" + courseTypes +
            ", author=" + author +
            ", text='" + text + '\'' +
            ", status=" + status +
            '}';
  }
}

